package n2524;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	
	static int N=50001;
	
	static int[] father=new int[N];
	static int[] rank=new int[N];
	
	static void makeSet(int x)
	{
		father[x]=x;
		rank[x]=1;
	}
	
	static int find(int x)
	{
		if(father[x]!=x)father[x]=find(father[x]);
		return father[x];
	}
	
	static void union(int x,int y)
	{
		x=find(x);
		y=find(y);
		if(x==y)return;
		if(rank[x]<rank[y])
		{
			father[x]=y;
			rank[y]+=rank[x];
		}else {
			father[y]=x;
			rank[x]+=rank[y];
		}
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub

		BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
		
		String line=null;
		int Case=0;
		while((line=bf.readLine())!=null)
		{
			
			StringTokenizer st=new StringTokenizer(line);
			int n=Integer.parseInt(st.nextToken());
			int p=Integer.parseInt(st.nextToken());
			if(n==0&&p==0)break;
			for(int i=0;i<n;i++)makeSet(i);
			for(int i=0;i<p;i++)
			{
				line=bf.readLine();
				StringTokenizer st2=new StringTokenizer(line);
				int x=Integer.parseInt(st2.nextToken());
				int y=Integer.parseInt(st2.nextToken());
				union(x,y);
			}
			//output
			int count=0;
			for(int i=0;i<n;i++)
			{
				if(father[i]==i)count++;
			}
			System.out.println("Case "+(++Case)+": "+count);
		}
	}

}
